package com.feihong.yw189.adapter.Kuandai;


import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.feihong.yw189.R;
import com.feihong.yw189.model.Kaika.BaozhuangEditModel;

import java.util.ArrayList;

/**
 * 报装地址
 */

public class EditBaoZhuangAdapter extends BaseAdapter{
    private int selectPosition;
    private Context mContext;
    private int layoutResourceId;
    ArrayList<BaozhuangEditModel.DataBean.ListBean> listBeans=new ArrayList<>();


    public EditBaoZhuangAdapter(Context mContext, int layoutResourceId, ArrayList<BaozhuangEditModel.DataBean.ListBean> listBeans) {
        this.mContext = mContext;
        this.layoutResourceId = layoutResourceId;
        this.listBeans = listBeans;
    }

    public void setDataList(ArrayList<BaozhuangEditModel.DataBean.ListBean> list){
        this.listBeans=list;
        notifyDataSetChanged();
    }
    public void changeState(int position) {
        // 更新状态
        selectPosition = position;
        // 更新adapter
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return listBeans.size();
    }

    @Override
    public Object getItem(int Position) {
        return listBeans.get(Position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder  holder;
        if(convertView == null){
            LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.dire_name= (TextView) convertView.findViewById(R.id.tv_hotsearch);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        if(selectPosition == position){
            holder.dire_name.setBackgroundResource(R.drawable.kuandai_btn_selected);
            holder.dire_name.setTextColor(Color.parseColor("#ffffff"));
        }else{
            holder.dire_name.setBackgroundResource(R.drawable.kuandai_btn_sulv);
            holder.dire_name.setTextColor(Color.parseColor("#028BE6"));
        }
        BaozhuangEditModel.DataBean.ListBean  item=listBeans.get(position);
        holder.dire_name.setText(item.getDire_name());
        return convertView;
    }
   static  class ViewHolder{
        private TextView dire_name;
        private String dire_no;
      }
}
